package com.bishe.cyh.controller;

import com.bishe.cyh.mode.Loginfaceadd;
import com.bishe.cyh.mode.Result;
import com.bishe.cyh.service.LoginService;
import com.bishe.cyh.utils.Base64Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.PostConstruct;

/**
 * @Author: Poppin
 * @Date: 2022/1/16 22:17
 * @Version: 1.0
 */
@RestController
@RequestMapping("/api")
public class LoginController {

    private LoginService loginService;

    @Autowired
    public void setLoginService(LoginService loginService){
        this.loginService=loginService;
    }

    @PostConstruct
    public void init(){
        loginService.initFace();
        System.out.println("执行加载了");
    }

    @PostMapping("/LoginRe")
    public Result Login(@RequestBody String baseImage) throws Exception {
        byte[] imageData = Base64Util.base64ToBytes(baseImage);
        return loginService.Login(imageData);
    }

    @PostMapping("/Face")
    public Result Facerec(@RequestParam(value = "file") MultipartFile file) throws Exception {

        return loginService.FaceReco(file);
    }
    @PostMapping("/Add")
    public Result Addyg(@RequestBody Loginfaceadd loginfaceadd) throws Exception {
        return loginService.FaceAdd(loginfaceadd);
    }
    @GetMapping("/yglist")
    public Result LISTinfo(){
        return loginService.Getyginfo();
    }
    @GetMapping("/deleteyg")
    public Result DeleteYg(@RequestParam("id")Integer id){
        return loginService.DELETE(id);
    }

}
